package cn.wolfcode.trip.admin.controller;

import cn.wolfcode.trip.base.util.UploadUtil;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("images")
public class ImagesController {
   @RequestMapping(method = RequestMethod.POST)
    public Map upload(MultipartFile upload ){
        HashMap<Object, Object> map = new HashMap<>();
        try {
            String imgUrl = UploadUtil.upload(upload, UploadUtil.PATH + "/upload/");
            map.put("uploaded",1);
           map.put("url",imgUrl);
     }catch (Exception e){
            e.printStackTrace();
            map.put("uploaded",0);
            HashMap<Object, Object> error = new HashMap<>();
            error.put("message","上传失败");
            map.put("error",error);

     }
     return map;
     }
}
